/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jeffoldwork;

import java.io.BufferedInputStream;
import java.net.URL;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Alex Koutmos
 */
public class ThreadDownloader extends Thread {

    public void run() {
        try {
            //Declaration of variables

            String url = "http://auranet.no-ip.org/";
            String filename = "Characters.zip"; // parse here to get filename from url
            String destination = "C:\\Riot Games\\League of Legends\\game\\DATA\\";

            BufferedInputStream getFile = new BufferedInputStream(new URL(url + filename).openStream());
            BufferedOutputStream writeFile = new BufferedOutputStream(new FileOutputStream(destination+filename), 1024);

            int oneChar, count = 0;
            while ((oneChar = getFile.read()) != -1) {
                writeFile.write(oneChar);
                count++;
            }

            writeFile.close();
            getFile.close();
            writeFile = null;
            getFile= null;

           Unzip.unzip(destination+filename) ;
        }
        catch(Exception e) {
            System.out.println("Fail");
        }
        finally {
            System.gc();
        }
    }
}
